﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CoolCode.Controls;
using CoolCodePFM.TranRef; 

namespace CoolCodePFM
{
    public partial class TranList : UserControl
    {
         TranServiceClient client;

        public TranList()
        {
            InitializeComponent();
            this.pager.PageCount = 34;
            this.pager.OnPageIndexChange += new PageIndexChange(pager_OnPageIndexChange);
            client = new TranServiceClient();
            client.GetTransCompleted += new EventHandler<GetTransCompletedEventArgs>(client_GetTransCompleted);
            Window.ShowLoading();
            client.GetTransAsync();
          
        }

        void client_GetTransCompleted(object sender, GetTransCompletedEventArgs e)
        {
            this.grdTranList.ItemsSource = e.Result;
            Window.HideLoading();
        }

        void pager_OnPageIndexChange(int pageIndex)
        {
            this.pageIndex = pageIndex;
          //  this.getProductListTask.Start();
        }

        private void opPanal_MouseEnter(object sender, MouseEventArgs e)
        {
            this.opPanal.Opacity = 1;
        }

        private void opPanal_MouseLeave(object sender, MouseEventArgs e)
        {
            this.opPanal.Opacity = 0.8;
        }

        //private ObservableCollection<Product> products;
        //private List<Category> categorys;
        private int pageIndex = 1;


        void OnCreate(object sender, MouseButtonEventArgs e)
        {
            //ProductEdit editPanel = new ProductEdit();
            //editPanel.Categorys = this.categorys;

            //Window.ShowOpPanel(
            //    "Add Product",
            //    editPanel,
            //    panel =>
            //    {
            //        this.products.Insert(0, editPanel.Product);

            //        //this.addProductTask.Start();
            //    });
        }

        void OnUpdate(object sender, MouseButtonEventArgs e)
        {
            //ProductEdit editPanel = new ProductEdit();
            //editPanel.Categorys = this.categorys;
            //editPanel.Product = this.productList.SelectedItem as Product;

            //Window.ShowOpPanel(
            //    "Update Product",
            //    editPanel,
            //    panel =>
            //    {
            //        //this.updateProductTask.Start();
            //    });
        }

        void OnDelete(object sender, MouseButtonEventArgs e)
        {
            //var deleteProducts = products.Where(p => p.Checked).ToList();
            //if (deleteProducts.Count == 0)
            //{
            //    Window.Alert("Please checked the rows u want to delete");
            //}
            //else
            //{
            //    Window.Confirm(
            //        "Do u confirm to delete checked products?",
            //        () =>
            //        {
            //            foreach (Product p in deleteProducts)
            //                this.products.Remove(p);

            //            //this.deleteProductTask.Start();
            //        }
            //    );
            //}
        }

        void OnRefresh(object sender, MouseButtonEventArgs e)
        {
            client.GetTransAsync();
        }
    }
}
